﻿using System;
using WebUI.BL.Coupon;

namespace WebUI.AdminSite.Coupon
{
    public partial class CouponMgmt : System.Web.UI.Page
    {
        public string datefrom = "";
        public string dateto = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
                datefrom = DateTime.Now.AddDays(-7).ToString("dd/MM/yyyy");
                dateto = DateTime.Now.ToString("dd/MM/yyyy");
            }
        }

        private void BindData()
        {
            WebUI.Helpers.WebFunction function = new Helpers.WebFunction();

            string couponname = txtCouponName.Text.Trim();
            string productcategory = txtProductCategory.Text.Trim();
            string product = txtProduct.Text.Trim();
            var datestarttemp = Request.Form["txtfromdate"];
            if (datestarttemp != "" && datestarttemp != null)
                datefrom = function.Convert_ddMMyyyy_MMddyyyy(datestarttemp).ToString();
            else
                datefrom = DateTime.Now.AddDays(-7).ToString("MM/dd/yyyy");

            var endstarttemp = Request.Form["txttodate"];
            if (endstarttemp != "" && endstarttemp != null)
                dateto = function.Convert_ddMMyyyy_MMddyyyy(endstarttemp).ToString();
            else
                dateto = DateTime.Now.ToString("MM/dd/yyyy");
            string status = drpStatus.SelectedValue;

            CouponBL repository = new CouponBL();
            grdCoupon.DataSource = repository.Get_Admin_Coupon(couponname, productcategory, product, datefrom, dateto, status);
            grdCoupon.DataBind();
        }

        protected void btnSearchClick(object sender, EventArgs e)
        {
            BindData();
        }
    }
}